<?php
/**
 * ExtLoginProvider class file.
 *
 * @author TrueSoftware B.V. (The Netherlands)
 * @link http://www.ext4yii.com
 * @copyright Copyright 2007-2010 TrueSoftwareB.V. all rights reserved.
 * @license http://www.ext4yii.com/license/
 *          EVALUATION VERSION - NOT FOR COMMERCIAL USE OR DISTRIBUTION.
 * @version 0.7.2
 */

class ExtLoginProvider extends CWidget
{
    public $controller;
    public $view='basic';
    public $theme;

    public function init()
    {
        parent::init();
        
        $jsfile = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'js' . DIRECTORY_SEPARATOR . 'ExtLoginProvider.js';
        $fname = 'extloginprovider-' . Yii::app()->language . (YII_DEBUG ? '-debug.js' : '.js');
        $file = Yii::app()->getAssetManager()->basePath . DIRECTORY_SEPARATOR . $fname;

        if(!file_exists($file))
        {
            $content = $this->getController()->renderInternal($jsfile,null,true);
            if(YII_DEBUG)
                file_put_contents ($file, $content);
            else
                file_put_contents ($file, ExtHelper::packScript($content));
        }

        $url = Yii::app()->getAssetManager()->baseUrl.'/'.$fname;
        
        $this->getController()->addUxScript(array(
            'sm'=>true,
            'file'=>$url
        ));
    }
    
    public function run()
    {
        $this->render($this->view, array(
            'controller'=>$this->controller,
            'theme'=>$this->theme
        ));
    }
}
?>
